<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="top_header_left">
        <el-input v-model="medal_index.keyword" placeholder="礼物名称" style="width:200px;margin-right: 20px" />
        <el-button class="filter-item" type="primary" icon="el-icon-search"
          @click="medal_index.page = 1;handleFilter()">
          搜索
        </el-button>
      </div>
      <div class="top_header_right">
        <el-button class="filter-item" type="primary" style="margin-left: 20px" @click="setUp(1)">
          新增
        </el-button>
      </div>
    </div>

    <el-table ref="multipleTable" :data="list" stripe style="width: 1400px" border>
      <el-table-column prop="id" label="id" width="80" align="center" :show-overflow-tooltip='true' />
      <el-table-column prop="name" label="名称" align="center" :show-overflow-tooltip='true' />
      <el-table-column prop="icon_full" label="勋章图片" width="200" align="center">
        <template align="center" slot-scope="scope">
          <div class="demo-image__preview">
            <el-image v-if="scope.row.icon_full" class="my-img" :src="scope.row.icon_full" ref="myImg"
              :preview-src-list="srcList" @click="handlePriveImg(scope.row.icon_full)" @click.stop="handleClickItem">
            </el-image>
            <span v-else>无</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="long_icon_full" label="勋章长图" width="200" align="center">
        <template align="center" slot-scope="scope">
          <div class="demo-image__preview long_icon">
            <el-image v-if="scope.row.long_icon_full" class="my-img" :src="scope.row.long_icon_full" ref="myImg"
              :preview-src-list="srcList" @click="handlePriveImg(scope.row.long_icon_full)"
              @click.stop="handleClickItem">
            </el-image>
            <span v-else>无</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="small_icon_full" label="勋章小图" width="200" align="center">
        <template align="center" slot-scope="scope">
          <div class="demo-image__preview">
            <el-image v-if="scope.row.small_icon_full" class="my-img" :src="scope.row.small_icon_full" ref="myImg"
              :preview-src-list="srcList" @click="handlePriveImg(scope.row.small_icon_full)"
              @click.stop="handleClickItem">
            </el-image>
            <span v-else>无</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="parent_id" label="是否主勋章" align="center">
        <template align="center" slot-scope="scope">
          <span v-if="scope.row.parent_id == 0">是</span>
          <span v-else>否</span>
        </template>
      </el-table-column>
      <el-table-column prop="sort" label="排序" align="center" />
      <el-table-column prop="wall_show" label="勋章墙是否显示" align="center">
        <template align="center" slot-scope="scope">
          <span v-if="scope.row.wall_show == 1">是</span>
          <span v-else>否</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200" align="center">
        <template align="center" slot-scope="scope">
          <el-button type="button" size="small" @click="setUp(2,scope.row)">
            编辑
          </el-button>
          <el-button type="button" size="small" @click="medalSend_(scope.row)">
            发放
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="medal_index.page" :limit.sync="medal_index.pageSize"
      @pagination="handleFilter" />

    <el-dialog title="发放" :visible.sync="dialogFormVisible1" style="width:800px;margin:0 auto;" class="model_">
      <div class="center_lisr">
        <div>
          <div class="box_left">用户id</div>
          <el-input v-model="add_match.perfectNumber" placeholder="用户id" style="width:300px;max-width:70%;" type="number" />
        </div>
        <div>
          <div class="box_left">时间</div>
          <el-input v-model="add_match.days" placeholder="时间" style="width:300px;max-width:70%;" type="number" />
        </div>

      </div>
      <div>
        <el-button class="filter-item" type="primary" style="width:100%;margin:0 auto;margin-top:10px" @click="baocun">
          发放
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
  import {
    encryption2
  } from "@/api/index";
  export default {
    name: "medal",
    components: {
      Pagination,
    },
    data() {
      return {

        total: 0,
        calendarTypeOptions1: [],
        list: [],
        time_list: {},

        add_match: {
          perfectNumber:'',
          days:'',
        },
        medal_index: {
          type: 0,
          keyword: '',
          page: 1,
          pageSize: 10,
        },
        dialogFormVisible1: false,
        srcList: [],
        fileList: [],
        item_username: {}, //发放内容
      };
    },

    created() {
      this.handleFilter();
    },

    methods: {
      baocun() {
        const arys = {
          perfectNumber: this.add_match.perfectNumber,
          days: this.add_match.days,
          medalId: this.item_username.id,
        };
        const url = "/medal/medalSend";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.dialogFormVisible1 = false;
            this.add_match.perfectNumber = '',
            this.add_match.days = '',
              this.$message({
              message: res.data.text,
              type: "success",
            });
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
    },
    medalSend_(item) {
      // console.log(item);
      this.dialogFormVisible1 = true;
      this.item_username = item;
    },
    handlePriveImg(row) {
      this.srcList = []
      this.srcList.push(row); //将后端的这一行的数据push进数组中
      this.$refs.myImg.clickHandler();
    },
    // 获取图片遮罩层dom
    handleClickItem() {
      setTimeout(function () {
        let domImageMask = document.querySelector(".el-image-viewer__wrapper");
        if (!domImageMask) {
          return;
        }
        domImageMask.addEventListener("click", (e) => {
          if (e.target.parentNode.className == 'el-image-viewer__actions__inner' || e.target.parentNode
            .className == 'el-image-viewer__btn el-image-viewer__next' || e.target.parentNode.className ==
            'el-image-viewer__btn el-image-viewer__prev') {
            return; //如果点击底部菜单，不关闭
          }
          // 点击遮罩层时调用关闭按钮的 click 事件
          document.querySelector(".el-image-viewer__close").click();
          document.querySelector('body').setAttribute('style', 'overflow:auto;')
        });
      }, 300)
    },

    setUp(type, row) {
      this.$router.push({
        path: '/medal/details',
        name: 'details',
        query: {
          type: type,
          row: row,
        }
      })
    },
    // 查询
    handleFilter() {
      const arys = {
        type: this.medal_index.type,
        keyword: this.medal_index.keyword,
        page: this.medal_index.page,
        pageSize: this.medal_index.pageSize,
      };
      const url = "/medal/medalList";
      encryption2(arys, url).then((res) => {
        if (res.data.status === 0) {
          this.list = res.data.result.list;
          this.total = res.data.result.total;
        } else {
          this.$message({
            message: res.data.text,
            type: "error",
          });
        }
      });
    },
  },
  };
</script>
<style scoped>
  .filter-container .filter-item {
    margin-bottom: 0;
  }

  .el-table--border {
    border-right: 1px solid #dfe6ec;
  }

  .el-alert {
    width: 1400px;
  }

  .filter-container {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 1400px;
  }

  .batch {
    width: 1200px;
    margin: 10px 0;
    display: flex;
    flex-direction: row-reverse;
  }

  .batch .filter-item {
    margin-left: 20px;
  }



  .flex_de>div {
    display: flex;
    flex-direction: column;
  }

  .center_lisr>div {
    display: flex;
    width: 100%;
    align-items: center;
    /* justify-content: space-between; */
    margin: 18px 0;
  }

  .center_lisr>div>el-input {
    flex: 1;
    margin-left: 20px;
  }

  .box_left {
    width: 80px;
    height: 40px;
    display: flex;
    align-items: center;
  }

  .model_ /deep/ .el-dialog__body {
    padding-top: 0%;
  }

  .model_ /deep/ .el-button--mini {
    padding: 10px 20px;
  }

  .model_ /deep/ .el-dialog {
    border-radius: 4px;
  }

  .model_ /deep/ .el-input__inner {
    /* text-align: center; */
  }

  .flex_de /deep/ .el-input__inner {
    padding: 0 4px;
    border: 0;
    background: 00000000;
  }

  .new_row {
    width: 80%;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #333;
    font-weight: blod;
    font-family: serif;
    cursor: pointer;
  }

  .my-img {
    width: 80px;
    /* height: 80px; */
    padding: 10px;
    margin-right: auto;
  }

  .image_new_100 {
    height: 100px;
    display: flex;
    align-items: center;
  }

  .image_new_100>img {
    width: 50px;
    margin-right: 10px;
  }

  .demo-image__preview {}

  .long_icon .my-img {
    width: 150px;
  }
</style>